"""
入场三级教育
"""
import logging

import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool

# 未输入账户
@pytest.mark.业务系统
@pytest.mark.施工管理
#@pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright) -> None:
    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    allure.step("登录")
    page.goto(url)
    page.get_by_placeholder("请输入用户名").fill(username_admin)
    page.get_by_placeholder("请输入密码").fill(password_admin)
    page.get_by_role("button", name="登 录").click()
    
    allure.step("跳转农民工台账URL")
    page.goto(url + url_nongmingongtaizhang)
    page.get_by_role("tree").get_by_text(bd_zhihuigu).click()
    page.get_by_role("button", name=" 新建").click()
    page.locator("form").filter(
        has_text="基础信息所属标段项目法人标段3玉林联合体施工标项目法人标段").get_by_placeholder("请输入姓名").fill(
        "AutoTest-施工人员")
    page.get_by_placeholder("请输入身份证号").fill("430381199005134135")
    page.locator("label").filter(has_text="性别").click()
    page.get_by_role("textbox", name="请输入联系方式").fill("18075855172")
    page.get_by_placeholder("请输入工种").fill("工种1")
    page.locator("form").filter(
        has_text="基础信息所属标段项目法人标段3玉林联合体施工标项目法人标段").get_by_placeholder("请输入所属班组").fill(
        "班组1")
    page.get_by_placeholder("请输入所属单位").fill("所属单位1")
    page.get_by_placeholder("请输入证书名称").fill("证书1")
    page.get_by_placeholder("请输入证书编号").fill("证书编号1")
    page.get_by_placeholder("请选择证书有效期").fill("2024-01-01")
    page.get_by_placeholder("请选择证书有效期").press("Enter")
    page.get_by_placeholder("请选择入场时间").fill("2024-01-01")
    page.get_by_placeholder("请选择入场时间").press("Enter")
    page.get_by_placeholder("请选择出场日期").fill("2024-01-01")
    page.get_by_placeholder("请选择出场日期").press("Enter")
    page.get_by_placeholder("请输入备注").fill("备注1")
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("新建成功！")

    ######入场三级教育
    allure.step("跳转入场三级教育URL")
    page.goto(url + url_ruchangsanjijiaoyu)
    page.get_by_placeholder("请选择标段").click()
    page.get_by_text(bd_zhihuigu).nth(1).click()
    page.get_by_role("button", name=" 新建").click()
    page.get_by_label("请选择标段").get_by_text(bd_zhihuigu).click()
    page.get_by_role("button", name="确 定").click()
    page.locator("form").filter(has_text="所属标段项目法人标段3玉林联合体施工标项目法人标段2").get_by_placeholder(
        "请输入培训名称").fill("AutoTest-培训名称")
    page.get_by_placeholder("培训开始时间").click()
    page.get_by_placeholder("开始日期").fill("2024-03-21")
    page.get_by_placeholder("结束日期").fill("2024-03-22")
    page.get_by_role("button", name="确定").click()
    page.get_by_role("textbox", name="请输入培训时长").fill("10")
    page.locator("form").filter(has_text="所属标段项目法人标段3玉林联合体施工标项目法人标段2").get_by_placeholder(
        "请输入培训讲师").fill("讲师1")
    page.get_by_placeholder("请选择培训对象").click()
    page.get_by_placeholder("请输入用户账号").fill("AutoTest-施工人员")
    page.get_by_placeholder("请输入用户账号").press("Enter")
    page.get_by_role("group").get_by_text("AutoTest-施工人员").click()
    page.get_by_label("请选择培训对象").get_by_role("button", name="确 定").click()
    page.get_by_placeholder("请输入培训内容").fill("培训内容")
    page.get_by_role("textbox", name="请输入成绩").fill("50")
    page.locator("#app").get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("新建成功！")
    page.wait_for_timeout(3000)

    page.get_by_role("textbox", name="请输入培训名称").fill("AutoTest-培训名称")
    page.get_by_role("button", name=" 查询").click()
    page.wait_for_timeout(500)
    page.get_by_role("button", name="删除").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("删除成功！")

    allure.step("跳转农民工台账URL")
    page.goto(url + url_nongmingongtaizhang)
    page.get_by_role("textbox", name="请输入姓名").fill("AutoTest-施工人员")
    page.get_by_role("button", name=" 查询").click()
    page.wait_for_timeout(500)
    page.get_by_role("button", name="删除").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("删除成功！")
    context.close()
    SetupTeardown.close()